#include "junix.h"
#include <sys/shm.h>
#include <sys/ipc.h>

int main(int argc, char **argv)
{
	if(argc!=2)
		err_quit( "Usage:%s file", argv[0] );

	key_t key=ftok(argv[1],0);
	if(key==-1)
		err_sys("ftok");

	int shmid=shmget(key,0,0644);
	if(shmid==-1)
		err_sys("shmget");

	char* p=shmat(shmid, NULL, 0);
	if(p==NULL)
		err_quit("shmat error");

	struct shmid_ds buf;
	if( shmctl(shmid,IPC_STAT,&buf) < 0 )
		err_sys("shmctl");

	int i;
	for(i=0;i<buf.shm_segsz;++i)
		*p++=i%256;

	exit(1);

	return 0;
}

